package com.lbj.mall.order.config;

import com.lbj.mall.order.interceptor.UserLoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class AppMVCConfig implements WebMvcConfigurer {

    @Autowired
    private UserLoginInterceptor userLoginInterceptor;

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        /**
         * 之前我们会在controller中写很多的空方法就是为了跳转，
         * 现在有了更优雅的操作，使用WebMvcConfigurer中的addViewControllers方法
         *     @GetMapping("/login.html")
         *     public String loginPage() {
         *         return "login";
         *     }
         *
         *     @GetMapping("/register.html")
         *     public String registerPage() {
         *         return "register";
         *     }
         */
        //registry.addViewController("login.html").setViewName("login");
        //registry.addViewController("register.html").setViewName("register");
        registry.addViewController("confirm.html").setViewName("confirm");
        registry.addViewController("detail.html").setViewName("detail");
        registry.addViewController("list.html").setViewName("list");
        registry.addViewController("pay.html").setViewName("pay");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 拦截所有请求
        registry.addInterceptor(userLoginInterceptor).addPathPatterns("/**");
    }
}
